<template>
  <view class="root">
    <view v-if="current === 0" class="content">
      <HomePage ref="homePageRef"></HomePage>
    </view>
    <view v-if="current === 1" class="content">
      <SalesIndex></SalesIndex>
    </view>
    <view v-if="current === 2" class="content">
      <SelfInfo></SelfInfo>
    </view>
    <AtTabBar
      fixed
      :tabList="tabList"
      :onClick="handleClick"
      :current="current"
      selectedColor="#6C63FF"
    />
  </view>
</template>

<script lang="ts">
import "./index.less";
import Taro from "@tarojs/taro";
import { AtTabBar } from "taro-ui-vue";
import HomePage from "../home/index.vue";
import SalesIndex from "../sales/index/index.vue";
import SelfInfo from "../self-info/index.vue";
export default {
  components: {
    HomePage,
    SalesIndex,
    AtTabBar,
    SelfInfo,
  },
  data() {
    return {
      current: 0,
      tabList: [
        { title: "首页", iconType: "home" },
        { title: "商城", iconType: "shopping-bag" },
        { title: "我的", iconType: "user" },
      ],
    };
  },
  methods: {
    tabSwitch1: function (value, index) {
      console.log(value, index);
    },
    handleClick(value) {
      this.current = value;
    },
    async getTotalScore() {},
    async getTaskList() {},
    async getPersonalHealthyData() {},
    gotoTaskBrief() {
      Taro.navigateTo({
        url: "",
      });
    },
    getGoalsData() {},
    getStepsFromWx() {
      Taro.getWeRunData({
        success: function (res) {
          // 拿 encryptedData 到开发者后台解密开放数据
          const encryptedData = res.encryptedData;
          // 或拿 cloudID 通过云调用直接获取开放数据
          const cloudID = res.cloudID;
        },
      });
    },
  },

  async created() {
    // this.getStepsFromWx();
  },
  mounted() {},

  // onLoad
  onLoad() {},

  // onReady
  onReady() {},

  // 对应 onShow
  onShow() {
    if (this.current === 0) {
      this.$refs.homePageRef.refresh();
    }
    const instance = Taro.getCurrentInstance();
    if (instance) {
      if (instance.router && instance.router.params.current) {
        this.current = instance.router.params.current - 0;
      }
    }
  },

  // 对应 onHide
  onHide() {},

  // 对应 onPullDownRefresh
  onPullDownRefresh() {},
};
</script>
<style lang="scss">
@import "~taro-ui-vue/dist/style/components/tab-bar.scss";
@import "~taro-ui-vue/dist/style/components/badge.scss";
@import "~taro-ui-vue/dist/style/components/icon.scss";
</style>
